package com.sunlands.zlcx.usercenter.domain;

import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;

import javax.persistence.*;
import java.io.Serializable;
import java.util.Date;

/**
 * @author shixiaopeng
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
@Entity(name = "tz_vip_user")
@DynamicUpdate
@DynamicInsert
public class VipUserDO implements Serializable {

    private static final long serialVersionUID = -5210975848079627189L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    /**
     * 用户表tz_user的id
     */
    private Long userId;

    /**
     * 生效日期
     */
    private Date takeEffectDate;

    /**
     * 过期日期
     */
    private Date expireDate;

    /**
     * 当月过期日期
     */
    private Date currExpireDate;
    /**
     * 预扣时长(用于切换扣费产品时使用)
     */
    private Long preUsedTime;
    /**
     * 当月使用时长
     */
    private Long useredTime;

    /**
     * 当月总时长
     */
    private Long totalTime;

    /**
     * @see LevelEnum
     * VIP用户等级
     */
    private Integer level;
    /**
     * 状态：1有效，0无效
     */
    private Integer status;

    @ApiModelProperty(value = "更新时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @Column(insertable = false, updatable = false)
    Date updateTime;

    @ApiModelProperty(value = "创建时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @Column(insertable = false, updatable = false)
    Date createTime;

    public enum StatusEnum {
        invalid(0, "无效"),
        valid(1, "有效");

        public final Integer code;
        public final String desc;

        StatusEnum(Integer code, String desc) {
            this.code = code;
            this.desc = desc;
        }
    }

    public enum LevelEnum {

        EXPERIENCE_TIMES(10, "体验", 0),
        VIP_COMMON(100, "VIP", 1),
        FREE_TIMES(150, "免费", 0),
        HOUR_TIMES(180, "加油卡", 1),
        VIP_7DAY(200, "冲刺卡", 1),
        STUDY_OPEN_DAY(300, "学习开放日", 0),
        ;

        public final Integer code;
        public final String desc;
        public final Integer vip;

        LevelEnum(Integer code, String desc, Integer vip) {
            this.code = code;
            this.desc = desc;
            this.vip = vip;
        }

        public static LevelEnum of(Integer code) {
            for (LevelEnum level : LevelEnum.values()) {
                if (code.equals(level.code)) {
                    return level;
                }
            }
            return null;
        }
    }
}
